import {call, put, take} from "redux-saga/effects";
import {TEMPLATE_POINT,DEMO_ID} from "./const";
import {getCurrent,getDemoId} from "../../services/new";

function* fetchCurrentPoint() {
    try {
        const rsp = yield call(getCurrent);
        const template_point = rsp.data;//rsp 调用接口拿到的数据
        yield put({
            type: TEMPLATE_POINT,//保存的地方：姓名
            payload: {
                template_point,
            },
        })
    } catch (e) {
        console.log(e);
    }
}

function* fetchDemoID() {
    try {
        const rsp = yield call(getDemoId);
        const demo_id = rsp.data;//rsp 调用接口拿到的数据
        yield put({
            type: DEMO_ID,//保存的地方：姓名
            payload: {
                demo_id,
            },
        })
    } catch (e) {
        console.log(e);
    }
}

export default function* saga() {
    // const {payload} = yield take(TEMPLATE_POINT);
    // yield call(fetchCurrentPoint);

    while (true) {
        yield take(TEMPLATE_POINT);
        yield call(fetchCurrentPoint);
    }
}
